package org.darcy.controller.base;

import java.util.List;

import org.darcy.controller.BaseController;
import org.darcy.entity.base.BaseDicType;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.framework.model.R;
import org.darcy.service.base.BaseDicTypeService;
import org.darcy.utils.common.ReturnCode;
import org.darcy.utils.vo.ReturnVo;
import org.darcy.vo.CheckExistVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "BaseDicType接口：数据字典类型")
@RestController
@RequestMapping("/base/dicType")
@Slf4j
public class BaseDicTypeController extends BaseController<BaseDicType> {

	private final String info_prefix = "[数据字典类型模块]";

	@Autowired
	private BaseDicTypeService dicTypeService;

	/**
	 * 判断字段是否存在
	 *
	 * @param checkExistVo 参数
	 * @return
	 */
	@PostMapping(value = "/checkEntityExist", produces = "application/json")
	protected R checkEntityExist(@RequestBody CheckExistVo checkExistVo) {
		return this.checkExist(dicTypeService, checkExistVo);
	}

	@Operation(summary = "所有数据字典类型")
	@PostMapping("getAll")
	public R getAll(@RequestBody BaseDicType param) {
		log.debug("{}-列表数据", info_prefix);
		List<BaseDicType> data = dicTypeService.getAll(param);
		return R.ok().data(data);
	}
	
	@Operation(summary = "数据字典类型分页列表")
	@PostMapping("list")
	public R list(@RequestBody PageParam<BaseDicType> param) {
		log.debug("{}-列表数据", info_prefix);
		PageData<BaseDicType> data = dicTypeService.page(param);
		return R.ok().data(data);
	}

	@Operation(summary = "数据字典类型详情")
	@GetMapping("/view/{id}")
	public R view(@PathVariable Integer id) {
		log.debug("{}-查看数据字典类型信息", info_prefix);
		BaseDicType data = dicTypeService.getById(id);
		return R.ok().data(data);
	}

	/**
	 * 添加或者修改
	 *
	 * @param dicType 参数
	 * @return
	 */
	@PostMapping(value = "/saveOrUpdate", produces = "application/json")
	public ReturnVo<String> saveOrUpdate(@RequestBody BaseDicType dicType) {
		ReturnVo<String> returnVo = new ReturnVo<>(ReturnCode.SUCCESS, "OK");
		if (dicType.getId() == null) {
			dicTypeService.insert(dicType);
		} else {
			dicTypeService.update(dicType);
		}
		return returnVo;
	}

	@Operation(summary = "根据ID删除客户应用")
	@PostMapping("/del/{id}")
	public R del(@PathVariable Integer id) {
		log.debug("{}-根据ID删除", info_prefix, id);
		dicTypeService.delete(id);
		return R.ok("删除成功");
	}

}
